package com.xgl.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xgl.mapper.StudentinfoMapper;
import com.xgl.pojo.Block;
import com.xgl.pojo.RespBean;
import com.xgl.pojo.RespPageBean;
import com.xgl.pojo.Studentinfo;
import com.xgl.service.IStudentinfoService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 * 学生个人信息 服务实现类
 * </p>
 *
 * @author 最最帅气的熊国林
 * @since 2021-05-09
 */
@Service
public class StudentinfoServiceImpl extends ServiceImpl<StudentinfoMapper, Studentinfo> implements IStudentinfoService {

    @Autowired
    private StudentinfoMapper studentinfoMapper;

    @Override
    public RespPageBean getStudentInfoByPage(Integer currentPage, Integer size, Studentinfo studentinfo, LocalDate[] beginDateScope) {
        //开启分页
        Page<Studentinfo> page = new Page<>(currentPage, size);
        IPage<Studentinfo> studentinfoIPage = studentinfoMapper.getStudentInfoByPage(page, studentinfo, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(studentinfoIPage.getTotal(), studentinfoIPage.getRecords());
        return respPageBean;
    }

    @Override
    public RespBean addStudentInfo(Studentinfo studentinfo) {
        if (studentinfoMapper.insert(studentinfo) == 1){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @Override
    public List<Studentinfo> getStudentInfo(Integer id) {
        return studentinfoMapper.getStudentInfo(id);
    }

    @Override
    public RespBean insertHashCode(Integer id,String hashCode) {
        if (studentinfoMapper.insertHashCode(id,hashCode) && studentinfoMapper.insertPreviousHash(id,hashCode)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @Override
    public boolean addNewBlock(Studentinfo studentinfo) {
        return false;
    }

    @Override
    public String getPreHash(Integer id) {
        return studentinfoMapper.getPreHash(id);
    }

//    @Override
//    public RespBean getHashCode(Integer id) {
//        Map<String,Object> list =  studentinfoMapper.getHashCode(id);
//        return RespBean.error("添加失败");
//    }
}
